#include <iostream>

using namespace std;

int main()
{
	int T;
	cin >> T;
	
	while (T -- )
	{
		int a, b;
		cin >> a >> b;
		
		if (b < 16) a = max(0, a - 10);
		else if (b > 20) a = max(0, a - (b - 20));
		
		cout << a << endl;
	}
	
	return 0;
}